using System.Collections.Generic;
using UnityEngine;

namespace BasicScript.Component
{
	public class MoveAnimAObject : MonoBehaviour
	{
		private List<Vector3> points = new List<Vector3>();

		private float speed = 1f;

		private float step;

		private bool isPlay;

		private int stage;

		private int curPointIndex;

		private float curAlpha;

		private SpriteRenderer spriteRender;

		private void Awake()
		{
			spriteRender = base.transform.GetComponent<SpriteRenderer>();
		}

		private void LateUpdate()
		{
			if (!isPlay)
			{
				return;
			}
			if (stage == 0)
			{
				SetSpriteAlpha(curAlpha + Time.deltaTime);
				if (curAlpha >= 1f)
				{
					stage = 1;
				}
			}
			else if (stage == 1)
			{
				step = speed * Time.deltaTime;
				base.transform.localPosition = Vector2.MoveTowards(base.transform.localPosition, points[curPointIndex], step);
				if (base.transform.localPosition.Equals(points[curPointIndex]))
				{
					if (curPointIndex >= points.Count - 1)
					{
						stage = 2;
					}
					else
					{
						curPointIndex++;
					}
				}
			}
			else
			{
				SetSpriteAlpha(curAlpha - Time.deltaTime);
				if (curAlpha <= 0f)
				{
					stage = 3;
					isPlay = false;
					DestroySelf();
				}
			}
		}

		public void SetPoints(List<Vector3> points)
		{
			this.points = points;
		}

		public void PlayAnim()
		{
			if (points.Count >= 2 && !(spriteRender == null))
			{
				isPlay = true;
				stage = 0;
				curPointIndex = 1;
				SetSpriteAlpha(0f);
				base.transform.localPosition = points[0];
			}
		}

		private void SetSpriteAlpha(float alpha)
		{
			curAlpha = alpha;
			if (spriteRender != null)
			{
				spriteRender.color = new Color(1f, 1f, 1f, alpha);
			}
		}

		public void DestroySelf()
		{
			if (base.gameObject != null)
			{
				Object.Destroy(base.gameObject);
			}
		}
	}
}
